<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="tag" uri="com.sand.myTag" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/public.css" media="all">

    <link rel="alternate icon" type="image/png" href="${pageContext.request.contextPath}/tokenpage/assets/i/favicon.png">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/tokenpage/assets/css/amazeui.min.css"/>

    <script src="${pageContext.request.contextPath}/tokenpage/assets/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/tokenpage/assets/js/amazeui.min.js"></script>
    <!-- UM相关资源 -->
    <link href="${pageContext.request.contextPath}/tokenpage/assets/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/tokenpage/assets/umeditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/tokenpage/assets/umeditor/umeditor.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/tokenpage/assets/umeditor/lang/zh-cn/zh-cn.js"></script>

</head>
<body>
<div id="main" >
    <!-- 聊天内容展示区域 -->
    <div id="ChatBox" class="am-g am-g-fixed">
        <div class="am-u-lg-12" style="height:800px;overflow-y:scroll;">
            <ul id="chatContent" class="am-comments-list am-comments-list-flip">
                <c:forEach items="${messageShow.list}" var="ite">
                    <c:if test="${messageShow.userId==ite.userId}">
                        <li id="msgtmp" class="" value="${ite.rid}" style="margin-top: 10px;margin-right: 20%;">
                            <a href="">
                                <img class="am-comment-avatar" src="${pageContext.request.contextPath}/layui/images/${messageShow.userAvatar}" alt=""/>
                            </a>
                            <div class="am-comment-main" >
                                <!-- 消息头部-格式代码 -->
                                <header class="am-comment-hd">
                                    <div class="am-comment-meta">
                                        <a ff="nickname" href="#link-to-user" class="am-comment-author">${messageShow.userName}</a>
                                        <time ff="msgdate" datetime="" title="">${ite.time}</time>
                                    </div>
                                </header>
                                <!-- 存放消息内容代码 -->
                                <div ff="content" class="am-comment-bd">${ite.content}</div>
                            </div>
                        </li>
                    </c:if>
                    <c:if test="${messageShow.landlordId==ite.userId}">
                        <li id="msgtmp" class="am-comment-flip" value="${ite.rid}" style="margin-left:20%;margin-top: 10px;">
                            <a href="">
                                <img class="am-comment-avatar" src="${pageContext.request.contextPath}/layui/images/${messageShow.avatar}" alt=""/>
                            </a>
                            <div class="am-comment-main" >
                                <!-- 消息头部-格式代码 -->
                                <header class="am-comment-hd">
                                    <div class="am-comment-meta">
                                        <a ff="nickname" href="#link-to-user" class="am-comment-author">${messageShow.name}</a>
                                        <time ff="msgdate" datetime="" title="">${ite.time}</time>
                                    </div>
                                </header>
                                <!-- 存放消息内容代码 -->
                                <div ff="content" name="content" class="am-comment-bd">${ite.content}</div>
                            </div>
                        </li>
                    </c:if>
                </c:forEach>
            </ul>
        </div>
    </div>
</div>


<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/jquery-3.3.1.js" charset="utf-8"></script>
<script>
    $(function (){
        //窗口大小变化时，调整显示效果
        $("#ChatBox div:eq(0)").height($(this).height()-290);
        $(window).resize(function(){
            $("#ChatBox div:eq(0)").height($(this).height()-290);
        });
        $("#ChatBox div:eq(0)").scrollTop(99);
    });
    layui.use(['form','dropdown', 'tableSelect', 'table', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            laydate = layui.laydate,
            dropdown = layui.dropdown,
            $ = layui.$;

        var rid=0;
        var ord=null;

        //右键菜单
        var inst = dropdown.render({
            elem: '#chatContent li' //也可绑定到 document，从而重置整个右键
            ,trigger: 'contextmenu' //contextmenu
            ,isAllowSpread: false //禁止菜单组展开收缩
            ,style: 'width: 200px' //定义宽度，默认自适应
            ,id: 'test777' //定义唯一索引
            ,data: [{
                title: '删除'
                ,id: '1'
            }, {
                title: '撤回'
                ,id: '2'
            }]
            ,click: function(obj, othis){
                if(obj.id === '1'){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/message/delMessagedetails",
                        type:"post",
                        data:"rid="+rid,
                        dataType:"text",
                        success:(rs)=>{
                            if(rs=="OK"){
                                layer.msg("删除成功",{icon:1,time:500},function (){
                                    $(ord).hide(200);
                                })
                            }else{
                                layer.msg("删除失败",{icon:2,time:500})
                            }
                        }
                    })
                }
            }
        });
        $("#chatContent li").click(function (){
            rid=this.value;
            ord=this;
            $(this).siblings("li").removeClass("am-comment-success");
            $(this).addClass("am-comment-success");
        })

    });
</script>
</body>
</html>